﻿@{
    ViewBag.Title = "Index";
}
<link href="../../Content/css/page_yk_index.css" rel="stylesheet" type="text/css" />
@Html.Partial("_PartviewAdminnav")
<div class="content bc">
    <div class="content_link_warn f12">
        你当前的位置：司机管理&gt&gt &nbsp;&nbsp;司机查询&gt&gt &nbsp;&nbsp;所有司机列表
    </div>
    <div class="content_right fr" id="rightcontent">
        <div class="column">
            <h4 class="title f14">
                数据库备份
            </h4>
        </div>
        <div class="maincontent">
            <div class="menuwrap">
                <div class="submenu">
                    @using (Html.BeginForm("Index", "Utility", FormMethod.Get, new { id = "SearchForm" }))
                    {
                        @Html.Hidden("Page");
                        <div class="box_name dil m010">
                            <span class="label">备份名</span> <span>
                                <input type="text" class="txt_name w100" id="input_name" title="输入备份名" />
                            </span>
                        </div>
                        <div class="box_date dil m010">
                            <span class="label">日期</span> <span>
                                <input type="text" class="txt_date bpdate" id="input_date" readonly="readonly" value=""
                                    title="备份时间" />
                            </span>
                        </div>
                        <div class="box_remark dil m010">
                            <span class="label">备注</span> <span>
                                <input type="text" class="w200 txt_remark" id="remark" title="输入备注" />
                            </span>
                        </div>
                        <div class="box_find dil m010">
                            <input type="button" class="btn_fc f14" id="backup" title="开始备份" value="备份" />
                        </div>
                    }
                </div>
            </div>
            <div class="driveinfolist tc overauto" id="backup_list">
                <table class="tb_list f14" id="backup_table">
                    <tr class="tr_head tf">
                        <th class="wp2">
                        </th>
                        <th id="th1" class="wp20 tc bdl">
                            文件名
                        </th>
                        <th id="th2" class="wp25 tc bdl">
                            备份时间
                        </th>
                        <th id="th3" class="wp30 tc bdl">
                            备注信息
                        </th>
                        <th class="hide_file">
                        </th>
                        <th id="th4" class="wp10 tc bdl">
                            还原
                        </th>
                        <th id="th5" class="wp10 tc bdl">
                            删除
                        </th>
                        <th class="wp2 bdl">
                        </th>
                    </tr>
                </table>
            </div>
        </div>
        <div id="background" class="background">
        </div>
        <div id="backup_loding" class="backup_loding">
            <div class="barbox">
                <div id="block_1" class="barlittle">
                </div>
                <div id="block_2" class="barlittle">
                </div>
                <div id="block_3" class="barlittle">
                </div>
                <div id="block_4" class="barlittle">
                </div>
                <div id="block_5" class="barlittle">
                </div>
            </div>
            <p id="backup_tip">
                数据备份中，请稍后…</p>
            <p id="restore_tip">
                数据还原中，请稍后…</p>
            <p id="delete_tip">
                数据删除中，请稍后…</p>
        </div>
    </div>
    @Html.Partial("_PartviewUtilityLeftbar")
    <div class="content_contract fl">
        <a href="javascript:void(0)" class="btn_contract w8h32" id="contract" title="收缩">
        </a><a href="javascript:void(0)" class="btn_expand w8h32" id="expand" title="展开">
        </a>
    </div>
    <div class="cb">
    </div>
</div>
<script type="text/javascript" src="../../Scripts/jquery-1.5.1.js"></script>
<script type="text/javascript">
    $(function () {
        $("tr:even").css("background-color", "#D7DBE4");
        var data = new Date().toLocaleString();
        $("#input_date").attr("value", data);

        var ajaxbg = $("#background,#backup_loding");
        $("#backup_tip").hide();
        $("#restore_tip").hide();
        $("#delete_tip").hide();
        ajaxbg.hide();

        $("#backup").click(function () {
            $("#backup_tip").show();
            ajaxbg.show();
            $.post("/Utility/Backup", { backupname: $("#input_name").val() },
                function (data) {
                    var remark = $("#remark").val();
                    $("#backup_tip").hide();
                    $("#restore_tip").hide();
                    $("#delete_tip").hide();
                    ajaxbg.hide();
                    alert(data.Message);
                    $("#backup_table").append("<tr>" + "<td></td><td>" + data.Backupname + "</td>" + "<td>" + data.Time + "</td>"
                        + "<td>" + remark + "</td>" + '<td class="hide_file">' + data.File + "</td>"
                        + "<td>" + '<input type="button" value="还原" class="restore rdstyle" />' + "</td>"
                        + "<td>" + '<input type="button" value="删除" class="delete rdstyle" />' + "</td><td></td>"
                        + "</tr>");
                });
        });

        $("#backup_list .restore").live("click", function () {
            if (confirm("您确认要恢复数据库吗?")) {
                $("#restore_tip").show();
                ajaxbg.show();
                $.post("/Utility/Restore", { "file": $(this).parent().prev().text() },
                function (data) {
                    $("#backup_tip").hide();
                    $("#restore_tip").hide();
                    $("#delete_tip").hide();
                    ajaxbg.hide();
                    alert(data.Message);
                });
            }
        });

        $("#backup_list .delete").live("click", function () {
            var $item = $(this).parent().parent();
            if (confirm("您确认要删除这个备份文件吗?")) {
                $("#delete_tip").show();
                ajaxbg.show();
                $.post("/Utility/Delete", { "file": $(this).parent().prev().prev().text() },
                function (data) {
                    $("#backup_tip").hide();
                    $("#restore_tip").hide();
                    $("#delete_tip").hide();
                    ajaxbg.hide();
                    alert(data.Message);
                    $item.remove();
                });
            }
        });

        $.post("/Utility/GetBackupFileList", {}, function (data) {
            $.each(data, function () {
                $("#backup_table").append("<tr>" + "<td></td><td>" + this.Backupname + "</td>" + "<td>" + this.Time + "</td>"
                        + "<td>" + "修改内容，更新备份" + "</td>" + '<td class="hide_file">' + this.File + "</td>"
                        + "<td>" + '<input type="button" value="还原" class="restore rdstyle" />' + "</td>"
                        + "<td>" + '<input type="button" value="删除" class="delete rdstyle" />' + "</td><td></td>"
                        + "</tr>");
            });
        });
    });
</script>
